package com.iot08.api.controller;

import com.iot08.api.annotation.CheckAppSign;
import com.iot08.api.controller.base.BaseController;
import com.iot08.api.response.WallpaperResp;
import com.iot08.api.service.UserWallpaperService;
import com.iot08.api.service.WallpaperService;
import com.iot08.api.vo.request.*;
import com.iot08.api.vo.request.base.BaseAccountReqVO;
import com.iot08.common.entity.app.UserWallpaper;
import com.iot08.common.utils.response.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author cwj
 * @description
 * @date 2025/3/10 10:28
 **/
@Slf4j
@RestController
@RequestMapping("getway/wallpaper")
public class WallpaperController extends BaseController {


    @Resource
    private WallpaperService wallpaperService;

    @Resource
    private UserWallpaperService userWallpaperService;

    /**
     * @description 查询壁纸信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/10 18:03
     **/
    @GetMapping("/query")
    public ResponseMap queryWallpaper(@Validated WallpaperQueryReqVo vo){
         return wallpaperService.queryWallpaper(vo);
    }


    /**
     * @description 查询用户已购买的图片
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/12 15:54
     **/
    @GetMapping("/queryUserWallpaper")
    public ResponseMap queryUserWallpaper(@Validated WallpaperQueryReqVo vo){
        //return wallpaperService.queryUserWallpaper(vo);
        return userWallpaperService.queryUserBoughtWallpaper(vo);
    }


    /**
     * @description 
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/12 15:55
     **/
    @GetMapping("/queryFreeWallpaper")
    public ResponseMap queryFreeWallpaper(@Validated WallpaperQueryReqVo vo){
        return wallpaperService.queryFreeWallpaper(vo);
    }

    
    /**
     * @description 查询热点图片
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/12 15:56
     **/
    @GetMapping("/queryHotspotWallpaper")
    public ResponseMap queryHotspotWallpaper(@Validated BaseAccountReqVO vo){
        List<WallpaperResp> wallpaperResps = wallpaperService.queryHotspotWallpaper();
        ResponseMap res = ResponseMap.success();
        res.put("hotspotWallpapers",wallpaperResps);
        return res;
    }

    /**
     * @description 按照分类查询壁纸信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/12 15:29
     **/
    @GetMapping("/queryByCategory")
    public ResponseMap queryWallpaperByCid(@Validated WallpaperQueryReqVo vo){
        return wallpaperService.queryWallpaperByCid(vo);
    }


    /**
     * @description 设置壁纸
     * @author cwj
     * @param [imei, vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/12 17:55
     **/
    @PostMapping("/settingWallpaper")
    public ResponseMap settingWallpaper(@Validated WallpaperSettingReqVo vo){
        return wallpaperService.settingWallpaper(vo);
    }


    /**
     * @description 购买壁纸
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/20 15:22
     **/
    @PostMapping("/buy")
    @CheckAppSign
    public ResponseMap buyWallpaper(@Validated @RequestBody WallpaperBuyerReqVo vo){
        return wallpaperService.buyWallpaper(vo.getBodyForm());
    }

    /**
     * @description 检查用户能否直接使用该壁纸
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/21 10:23
     **/
    @PostMapping("/check")
    public ResponseMap checkWallpaper(@Validated WallpaperCheckReqVo vo){
        return wallpaperService.checkWallpaper(vo);
    }

    /**
     * @description 新增壁纸
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/12 11:51
     **/
    @PostMapping("/add")
    public ResponseMap addWallpaper(@Validated WallpaperAddEditReqVo vo){
        return wallpaperService.addWallpaper(vo);
    }


    /**
     * @description 修改壁纸
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/12 11:51
     **/
    @PostMapping("/edit")
    public ResponseMap editWallpaper(@Validated WallpaperAddEditReqVo vo){
        return wallpaperService.editWallpaper(vo);
    }
}
